package org.itboys.mobile.controller.mobile;



import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.itboys.admin.entity.lasted.SundayArea;
import org.itboys.admin.service.lasted.SundayAreaService;
import org.itboys.admin.service.lasted.SundayUploadService;
import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * 作者：jiangxiong
 * 日期：2017年2月9日
 * 联系方式 ：empty90911@126.com
 * 描述：圣代_省市区_controller。
 * 
 */
@Controller
@RequestMapping("/sunday/mobile/area")
public class SundayMobileAreaController extends BaseController {


	@Autowired
	private SundayAreaService areaService;

	/**
	 *
	 * @param request
	 * @param response
	 * @param isIncludeTown//是否需要乡镇数据。如果是含有乡镇数据，不建议使用此方法
	 */
	@RequestMapping("/getAreaTree")
	@ApiOperation(value = "获取获取省/市/区县/乡镇街道四级行政地区。如果要获取乡镇街道数据，不建议使用此接口")
	public void getAreaTree(
			HttpServletRequest request,
			HttpServletResponse response,
			@ApiParam(required = true, name = "isIncludeTown", value = "是否包含乡镇街道数据。1是0否")@RequestParam(value="isIncludeTown",required=true)boolean isIncludeTown){


		try {

			List<SundayArea> result = areaService.getAreaTree(isIncludeTown);
			AjaxUtils.renderJsonporJson(response, null,
					ResultPageDOHelper.getMsgResultDO(result, CommonConstants.SUCCESS));
		} catch (Exception e) {
			e.printStackTrace();
			AjaxUtils.renderJsonporJson(response, null,
					ResultPageDOHelper.getMsgCodeResultDO(-1, CommonConstants.FAIL));
		}

	}

	/**
	 * 获取省
	 * @param request
	 * @param response
	 */

	@RequestMapping("/getProvince")
	@ApiOperation(value = "获取省一级地区")
	public void getProvince(
			HttpServletRequest request,
			HttpServletResponse response){
		try {

			List<SundayArea> result  = areaService.getProvince();
			AjaxUtils.renderJsonporJson(response, null,
					ResultPageDOHelper.getMsgResultDO(result, CommonConstants.SUCCESS));
		} catch (Exception e) {
			e.printStackTrace();
			AjaxUtils.renderJsonporJson(response, null,
					ResultPageDOHelper.getMsgCodeResultDO(-1, CommonConstants.FAIL));
		}

	}

	/**
	 * 获取市
	 * @param request
	 * @param response
	 * @param provinceId
	 */
	@RequestMapping("/getCity")
	@ApiOperation(value = "获取市一级地区")
	public void getCity(
			HttpServletRequest request,
			HttpServletResponse response,
			@ApiParam(required = true, name = "provinceId", value = "省ID")@RequestParam(value="provinceId",required=true)Long provinceId){

		try {

			List<SundayArea> result  = areaService.getCity(provinceId);
			AjaxUtils.renderJsonporJson(response, null,
					ResultPageDOHelper.getMsgResultDO(result, CommonConstants.SUCCESS));
		} catch (Exception e) {
			e.printStackTrace();
			AjaxUtils.renderJsonporJson(response, null,
					ResultPageDOHelper.getMsgCodeResultDO(-1, CommonConstants.FAIL));
		}

	}

	/**
	 * 获取区县
	 * @param request
	 * @param response
	 * @param cityId
	 */
	@RequestMapping("/getDistrict")
	@ApiOperation(value = "获取区县级地区")
	public void getDistrict(
			HttpServletRequest request,
			HttpServletResponse response,
			@ApiParam(required = true, name = "cityId", value = "市ID")@RequestParam(value="cityId",required=true)Long cityId){

		try {

			List<SundayArea> result  = areaService.getDistrict(cityId);
			AjaxUtils.renderJsonporJson(response, null,
					ResultPageDOHelper.getMsgResultDO(result, CommonConstants.SUCCESS));
		} catch (Exception e) {
			e.printStackTrace();
			AjaxUtils.renderJsonporJson(response, null,
					ResultPageDOHelper.getMsgCodeResultDO(-1, CommonConstants.FAIL));
		}

	}
	/**
	 * 获取乡镇街道级地区
	 * @param request
	 * @param response
	 * @param districtId
	 */
	@RequestMapping("/getTown")
	@ApiOperation(value = "获取乡镇街道级地区")
	public void getTown(
			HttpServletRequest request,
			HttpServletResponse response,
			@ApiParam(required = true, name = "districtId", value = "区县Id")@RequestParam(value="districtId",required=true)Long districtId){

		try {

			List<SundayArea> result  = areaService.getTown(districtId);
			AjaxUtils.renderJsonporJson(response, null,
					ResultPageDOHelper.getMsgResultDO(result, CommonConstants.SUCCESS));
		} catch (Exception e) {
			e.printStackTrace();
			AjaxUtils.renderJsonporJson(response, null,
					ResultPageDOHelper.getMsgCodeResultDO(-1, CommonConstants.FAIL));
		}

	}


}
